﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq; 

namespace MyHealthByDesignWebsite.Models
{
    public partial class NutritionProfile
    {
        //Description:  Model for Nutrition profile
        //Created:  Nov 2011
        //Programmer:  Bob Whiteis

        //pre-condition:  Nutrition Profile information has been submitted
        //post-condition:  False has been return if there is invalid information


        private FullDataSetDataContext db = new FullDataSetDataContext();//Added by Swathi Thopucherla

        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        //pre-condition:  Nutrition Profile information has been submitted
        //post-condition:  excepiton is thrown if invalid data was entered
        partial void OnValidate(ChangeAction action)
        {

            if (!IsValid)
            {
                throw new ApplicationException("Rule violations prevent saving");
            }
           
        }
        //pre-condition:  Nutrition Profile information has been submitted
        //post-condition:  List of rules violations is return
        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (NP_heightFt <= 0 || NP_heightFt == null)
                yield return new RuleViolation("Height must be greater than zero.", "NP_heightFt");
            if (NP_weight <= 0 || NP_weight == null)
                yield return new RuleViolation("Weight must be greater than zero", "NP_weight");
           // if (String.IsNullOrEmpty(AL_activityLevelID) || AL_activityLevelID == "0")
            //    yield return new RuleViolation("Activity level required", "AL_activityLevelID");
            yield break;
            
        }

        /**Below method added by Swathi Thopucherla
         * */
        public void insertNutritionProfile(NutritionProfile nutritionProfile)
        {
            db.NutritionProfiles.InsertOnSubmit(nutritionProfile);
            db.SubmitChanges();
            
        }

    }
}